import javax.swing.text.html.HTMLDocument;

class Task {
    private static final Object locker = new Object();
    public static int count = 1;
    public static int increatMent = 100;
    private static int currentThread = 1;

    static class PrintTask implements Runnable {
        private final  int threadId;
        public PrintTask(int threadId) {
            this.threadId = threadId;
        }
        @Override
        public void run() {
            while (true) {
                synchronized (locker) {
                    if (count > increatMent) {
                        locker.notifyAll();
                        break;
                    }
                    if (currentThread == threadId) {
                        if(threadId==1) {
                            System.out.println(Thread.currentThread().getName() + " " + "A");
                        } else if(threadId==2) {
                            System.out.println(Thread.currentThread().getName() + " " + "B");
                        } else {
                            System.out.println(Thread.currentThread().getName() + " " + "C");
                        }
                        count++;
                        currentThread = currentThread % 3 + 1;
                        locker.notifyAll();
                    } else {
                        try {
                            locker.wait();
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                            break;
                        }
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(new PrintTask(1), "THREAD-1");
        Thread t2 = new Thread(new PrintTask(2), "THREAD-2");
        Thread t3 = new Thread(new PrintTask(3), "THREAD-3");
        t1.start();
        t2.start();
        t3.start();
    }
}